#!/bin/sh

HERE="`dirname "$0"`"
cd "$HERE"

if [ "$WRAPPER_NAME" != "" ]; then
	export WRAPPER="$BUILT_PRODUCTS_PATH/$WRAPPER_NAME"
else
	export WRAPPER=../build/Release/PlugSuit.prefPane
fi

if [ ! -d "$WRAPPER" ]; then
	echo " !! $WRAPPER does not exist"
	exit 1
fi

mkdir -p build
mkdir -p build/_mount

hdiutil attach Template.dmg -readwrite -mountroot build/_mount -shadow build/_shadow -nobrowse
rsync -av --delete-after --delete "$WRAPPER" build/_mount/*/
hdiutil detach build/_mount/*

hdiutil convert Template.dmg -shadow build/_shadow -format UDZO -o build/PlugSuit.dmg -imagekey zlib-level=9

rmdir build/_mount
rm build/_shadow
